require 'socket'
require 'sendfile'

module Mongrel
  class HttpResponse
    
    # Uses the platform's native sendfile(2) command to stream the data.
    #
    # Requires the sendfile gem:
    # http://github.com/codeslinger/sendfile/tree/master
    #
    # This is not Rails, so do not put the sendfile gem dependency 
    # in environment.rb.
    #
    def send_file_with_native_sendfile(*args)      
      if /(solaris|linux|freebsd)/===RUBY_PLATFORM  # the gem's supported platforms
        File.open(args[0]) {|f| @socket.sendfile f }
        @body_sent = true
      else
        send_file_without_native_sendfile(*args)
      end
    end
    
    alias :send_file_without_native_sendfile :send_file
    alias :send_file :send_file_with_native_sendfile
    
  end
end
